//
//  CAnAlgGrandActivity.m
//  sr01sdkProject
//
//  Created by  on 2024/8/30.
//

#import "CAnAlgGrandActivity.h"

@implementation CAnAlgGrandActivity
-(NSNumber *)dataTimeStamp
{
    return @(self.timeStamp);
}

- (instancetype)initWithData:(NSData *)data
{
    self = [super init];
    if (self) {
        
        if (data.length < 20) {
            return self;
        }
        uint8_t *dataBytes = (uint8_t *)[data bytes];
        
        self->_cmdByte = dataBytes[1];
        
        // 2, 3, 4 年月日
        uint8_t year = dataBytes[2];
        uint8_t month = dataBytes[3];
        uint8_t day = dataBytes[4];
        
        _year = year+2000;
        _month = month;
        _day = day;
        
        NSDateFormatter *fmt = [NSDateFormatter new];
        fmt.dateFormat = @"yyyy-MM-dd";
        NSDate *date = [fmt dateFromString:[NSString stringWithFormat:@"%d-%02d-%02d",year+2000, month, day]];

        _timeStamp = (NSUInteger)(date.timeIntervalSince1970);
        
        // 5, 6  总的走路步数
        _totalWalkSteps = *((uint16_t *)(dataBytes + 5));
        
        // 7, 8 总的跑步步数
        _totalRunSteps = *((uint16_t *)(dataBytes + 7));
        
        // 9, 10 总的其它步数
        _totalOtherSteps = *((uint16_t *)(dataBytes + 9));
        
        _totalDistance = dataBytes[11] / 10.0f;
        // 12, 13 总能量
        _totalEnergy = *((uint16_t *)(dataBytes + 12));
        
        // 14, 15 总活动能量
        _totalActivityEnergy = *((uint16_t *)(dataBytes + 14));
        
        // 16, 17 当前能量消耗
        _met = *((uint16_t *)(dataBytes + 16)) / 10.0f;
         
        
    }
    return self;
}

@end
